Khai moves main window to QMainWindow from QDialog. Looks *way* better on Mac.
authorrobertl <robertl>
Thu, 23 Jul 2009 03:22:23 +0000 (03:22 +0000)
committerrobertl <robertl>
Thu, 23 Jul 2009 03:22:23 +0000 (03:22 +0000)
gui/app.pro
gui/main.cpp
gui/maindlg.cpp [deleted file]
gui/maindlg.h [deleted file]
gui/persistdlg.cpp [deleted file]
gui/persistdlg.h [deleted file]

index 4699eea83e9471d588c6aa9848be82adfd7b8658..194fb6bd69467e2504de61572c36d38ccf8be484 100755 (executable)
@@ -1,4 +1,4 @@
-# $Id: app.pro,v 1.3 2009/07/19 03:41:41 robertl Exp $
+# $Id: app.pro,v 1.4 2009/07/23 03:22:23 robertl Exp $
 #
 
 #CONFIG += qt debug console
@@ -31,7 +31,7 @@ extras.target = extras
 QMAKE_EXTRA_TARGETS += extras
 #POST_TARGETDEPS=extras
 
-FORMS += mainui.ui
+FORMS += mainwinui.ui
 FORMS += advui.ui
 FORMS += aboutui.ui
 FORMS += trackui.ui
@@ -50,8 +50,7 @@ SOURCES += gmapdlg.cpp
 SOURCES += aboutdlg.cpp
 SOURCES += main.cpp
 SOURCES += help.cpp
-SOURCES += maindlg.cpp
-SOURCES += persistdlg.cpp
+SOURCES += mainwindow.cpp
 SOURCES += format.cpp
 SOURCES += filterdata.cpp
 SOURCES += formatload.cpp
@@ -61,7 +60,7 @@ SOURCES += filterwidgets.cpp
 SOURCES += filterdlg.cpp
 
 
-HEADERS += maindlg.h
+HEADERS += mainwindow.h
 HEADERS += map.h
 HEADERS += gmapdlg.h
 HEADERS += gpx.h
@@ -74,7 +73,6 @@ HEADERS += help.h
 HEADERS += format.h
 HEADERS += formatload.h
 HEADERS += optionsdlg.h
-HEADERS += persistdlg.h
 HEADERS += processwait.h
 HEADERS += filterwidgets.h
 HEADERS += filterdata.h
index 79977304a4a95fbcd8ada2d590766511e5c430df..a20bb8bde1b9c4ddfd1ece7a6d81d92154c6ad52 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: main.cpp,v 1.2 2009/07/20 02:30:42 robertl Exp $
+// $Id: main.cpp,v 1.3 2009/07/23 03:22:24 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -28,7 +28,7 @@
 #include <QTranslator>
 #include <QIcon>
 
-#include "maindlg.h"
+#include "mainwindow.h"
 #include "gmapdlg.h"
 
 #ifdef _WIN32
@@ -68,9 +68,8 @@ int main(int argc, char**argv)
   QCoreApplication::setOrganizationDomain("gpsbabel.org");
   QCoreApplication::setApplicationName("GPSBabelFE");
 
-#ifdef XXX  
-#endif
-  MainDlg mainDlg(0);
-  mainDlg.exec();
+  MainWindow mainWindow(0);
+  mainWindow.show();
+  app->exec();
 }
 
diff --git a/gui/maindlg.cpp b/gui/maindlg.cpp
deleted file mode 100644 (file)
index 82dfb15..0000000
+++ /dev/null
@@ -1,967 +0,0 @@
-// -*- C++ -*-
-// $Id: maindlg.cpp,v 1.2 2009/07/19 06:52:23 robertl Exp $
-//------------------------------------------------------------------------
-//
-//  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
-//
-//  This program is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU General Public License as
-//  published by the Free Software Foundation; either version 2 of the
-//  License, or (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111
-//  USA
-//
-#include <QMessageBox>
-#include <QProcess>
-#include <QFileDialog>
-#include <QTextStream>
-#include <QSettings>
-#include <QTemporaryFile>
-
-#include "maindlg.h"
-#include "babeldata.h"
-#include "appname.h"
-#include "help.h"
-#include "advdlg.h"
-#include "aboutdlg.h"
-#include "optionsdlg.h"
-#include "filterdlg.h"
-#include "processwait.h"
-#include "formatload.h"
-#include "gmapdlg.h"
-
-#ifndef _WIN32
-static const char *deviceNames[] = {
-  "USB:",
-  "/dev/ttyS0",
-  "/dev/ttyS1",
-  "/dev/ttyS2",
-  "/dev/ttyS3",
-  0
-};
-#else
-static const char *deviceNames[] = {
-  "USB:",
-  "COM1:",
-  "COM2:",
-  "COM3:",
-  "COM4:",
-  0
-};
-#endif
-
-const int BabelData::noType = -1;
-const int BabelData::fileType = 0;
-const int BabelData::deviceType = 1;
-//------------------------------------------------------------------------
-static QString findBabelVersion()
-{
-  QProcess babel;
-  babel.start("gpsbabel", QStringList() << "-V");
-  if (!babel.waitForStarted())
-    return QString();
-  babel.closeWriteChannel();
-  if (!babel.waitForFinished())
-    return QString();
-
-  QString str = babel.readAll();
-  str.replace(QRegExp("^[\\s]*"),  "");
-  str.replace(QRegExp("[\\s]+$"),  "");
-  return str;
-}
-//------------------------------------------------------------------------
-static QStringList getCharSets()
-{
-  QProcess babel;
-  babel.start("gpsbabel", QStringList() << "-l");
-  if (!babel.waitForStarted())
-    return QStringList();
-  babel.closeWriteChannel();
-  if (!babel.waitForFinished())
-    return QStringList();
-
-  QStringList strList;
-  QTextStream tstream(babel.readAll());
-  while(!tstream.atEnd()) {
-    QString l = tstream.readLine();
-    if (QRegExp("^\\*").indexIn(l) == 0) {
-      l.replace(QRegExp("^[\\*\\s]*"),  "");
-      l.replace(QRegExp("[\\s]+$"),  "");
-      strList << l;
-    }
-  }
-  return strList;
-}
-
-//------------------------------------------------------------------------
-static QString MakeOptions(const QList<FormatOption>& options) 
-{
-  QString str;
-  for (int i=0; i<options.size(); i++) {
-    if (options[i].getSelected()) {
-      str += ",";
-      str += options[i].getName();
-      if (options[i].getType() != FormatOption::OPTbool) {
-       str += "=" + options[i].getValue().toString();
-      }
-    }
-  }
-  return str;
-}
-
-//------------------------------------------------------------------------
-static QString MakeOptionsNoLeadingComma(const QList<FormatOption>& options) 
-{
-  QString str = MakeOptions(options);
-  return (str.length()) ? str.mid(1) : str;
-    
-}
-//------------------------------------------------------------------------
-MainDlg::MainDlg(QWidget* parent): PersistentDialog(parent)
-{
-  loadFormats();
-  ui.setupUi(this);
-  setWindowTitle(appName);
-  babelVersion = findBabelVersion();
-  fmtChgInterlock = false;
-  loadDeviceNameCombos();
-  loadCharSetCombos();
-
-  connect(ui.inputFileOptBtn,        SIGNAL(clicked()), this, SLOT(inputFileOptBtnClicked()));
-  connect(ui.inputDeviceOptBtn,      SIGNAL(clicked()), this, SLOT(inputDeviceOptBtnClicked()));
-  connect(ui.inputFileNameBrowseBtn, SIGNAL(clicked()), this, SLOT(browseInputFile()));
-
-  ui.outputFileOptBtn->setAutoExclusive(false);
-  ui.outputDeviceOptBtn->setAutoExclusive(false);
-  connect(ui.outputFileOptBtn,        SIGNAL(clicked()), this, SLOT(outputFileOptBtnClicked()));
-  connect(ui.outputDeviceOptBtn,      SIGNAL(clicked()), this, SLOT(outputDeviceOptBtnClicked()));
-  connect(ui.outputFileNameBrowseBtn, SIGNAL(clicked()), this, SLOT(browseOutputFile()));
-  connect(ui.aboutButton, SIGNAL(clicked()), this, SLOT(aboutClicked()));
-  connect(ui.helpButton, SIGNAL(clicked()), this, SLOT(helpClicked()));
-
-  connect(ui.inputFormatCombo,  SIGNAL(currentIndexChanged(int)),
-         this,                 SLOT(inputFormatChanged(int)));
-  connect(ui.outputFormatCombo, SIGNAL(currentIndexChanged(int)),
-         this,                 SLOT(outputFormatChanged(int)));
-  connect(ui.inputOptionsBtn,   SIGNAL(clicked()),
-         this,                 SLOT(inputOptionButtonClicked()));
-  connect(ui.outputOptionsBtn , SIGNAL(clicked()),
-         this,                 SLOT(outputOptionButtonClicked()));
-  connect(ui.moreOptionButton , SIGNAL(clicked()),
-         this,                 SLOT(moreOptionButtonClicked()));
-
-  connect(ui.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(applyClicked()));
-  connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(rejectedClicked()));
-  connect(ui.xlateFiltersBtn, SIGNAL(clicked()), this, SLOT(filtersClicked()));
-
-  ui.buttonBox->button(QDialogButtonBox::Apply)->setIcon(QIcon(":images/runit.png"));
-  ui.buttonBox->button(QDialogButtonBox::Close)->setIcon(QIcon(":images/exit.png"));
-
-
-  ui.inputOptionsText->setReadOnly(true);
-  ui.outputOptionsText->setReadOnly(true);
-
-  ui.inputFileNameText->setReadOnly(true);
-  ui.outputFileNameText->setReadOnly(true);
-  ui.wayPtLabel->setText("");
-  ui.trackLabel->setText("");
-  ui.routeLabel->setText("");
-  lights[0] = QPixmap::fromImage(QImage(":images/00.png").scaledToHeight(20, Qt::SmoothTransformation));
-  lights[1] = QPixmap::fromImage(QImage(":images/01.png").scaledToHeight(20, Qt::SmoothTransformation));
-  lights[2] = QPixmap::fromImage(QImage(":images/10.png").scaledToHeight(20, Qt::SmoothTransformation));
-  lights[3] = QPixmap::fromImage(QImage(":images/11.png").scaledToHeight(20, Qt::SmoothTransformation));
-  
-  ui.outputWindow->setReadOnly(true);
-
-
-  //--- Restore from registry
-  restoreSettings();
-}
-
-//------------------------------------------------------------------------
-void MainDlg::loadDeviceNameCombos()
-{
-  ui.inputDeviceNameCombo->clear();
-  ui.outputDeviceNameCombo->clear();
-  for (int i=0; deviceNames[i]; i++) {
-    ui.inputDeviceNameCombo->addItem(deviceNames[i]);
-    ui.outputDeviceNameCombo->addItem(deviceNames[i]);
-  }
-}
-//------------------------------------------------------------------------
-void MainDlg::loadCharSetCombos()
-{
-  charSets = getCharSets();
-
-  ui.inputCharSetCombo->clear();
-  ui.outputCharSetCombo->clear();
-  ui.inputCharSetCombo->addItem(tr("default"), QVariant(-1));
-  ui.outputCharSetCombo->addItem(tr("default"), QVariant(-1));
-  for (int i=0; i<charSets.size(); i++) {
-    ui.inputCharSetCombo->addItem(charSets[i], QVariant(i));
-    ui.outputCharSetCombo->addItem(charSets[i], QVariant(i));
-  }
-}
-//------------------------------------------------------------------------
-void MainDlg::checkCharSetCombos()
-{
-  ui.inputCharSetCombo->setEnabled(bd.enableCharSetXform);
-  ui.outputCharSetCombo->setEnabled(bd.enableCharSetXform);
-  ui.inputCharSetCombo->setVisible(bd.enableCharSetXform);
-  ui.outputCharSetCombo->setVisible(bd.enableCharSetXform);
-}
-//------------------------------------------------------------------------
-void MainDlg::inputFileOptBtnClicked()
-{
-  fmtChgInterlock = true;
-  QString fmt = bd.inputFileFormat;
-  ui.inputStackedWidget->setCurrentWidget(ui.inputFilePage);
-  QList<int>indices = inputFileFormatIndices();
-  ui.inputFormatCombo->clear();
-  for (int i=0; i<indices.size(); i++) {
-    int k = indices[i];
-    ui.inputFormatCombo->addItem(formatList[k].getDescription(), QVariant(k));
-  }
-  setComboToFormat(ui.inputFormatCombo, fmt, true);
-  fmtChgInterlock = false;
-}
-
-//------------------------------------------------------------------------
-void MainDlg::inputDeviceOptBtnClicked() 
-{
-  fmtChgInterlock = true;
-  QString fmt = bd.inputDeviceFormat;
-  ui.inputStackedWidget->setCurrentWidget(ui.inputDevicePage);
-  QList<int>indices = inputDeviceFormatIndices();
-  ui.inputFormatCombo->clear();
-  for (int i=0; i<indices.size(); i++) {
-    int k = indices[i];
-    ui.inputFormatCombo->addItem(formatList[k].getDescription(), QVariant(k));
-  }
-  setComboToFormat(ui.inputFormatCombo, fmt, false);
-  fmtChgInterlock = false;
-}
-
-//------------------------------------------------------------------------
-void MainDlg:: outputFileOptBtnClicked()
-{
-  fmtChgInterlock = true;
-  if (ui.outputFileOptBtn->isChecked()) {
-    ui.outputFilePage->setEnabled(true);
-    ui.outputDeviceOptBtn->setChecked(false);
-    QString fmt = bd.outputFileFormat;
-    ui.outputStackedWidget->setCurrentWidget(ui.outputFilePage);
-    QList<int>indices = outputFileFormatIndices();
-    ui.outputFormatCombo->clear();
-    for (int i=0; i<indices.size(); i++) {
-      int k = indices[i];
-      ui.outputFormatCombo->addItem(formatList[k].getDescription(), QVariant(k));
-    }
-    setComboToFormat(ui.outputFormatCombo, fmt, true);
-  } 
-  else {
-    ui.outputStackedWidget->setCurrentWidget(ui.outputFilePage);
-    ui.outputFilePage->setEnabled(false);
-  }
-  fmtChgInterlock = false;
-}
-
-//------------------------------------------------------------------------
-void MainDlg:: outputDeviceOptBtnClicked()
-{
-  fmtChgInterlock = true;
-  if (ui.outputDeviceOptBtn->isChecked()) {
-    ui.outputDevicePage->setEnabled(true);
-    ui.outputFileOptBtn->setChecked(false);
-    QString fmt = bd.outputDeviceFormat;
-    ui.outputStackedWidget->setCurrentWidget(ui.outputDevicePage);
-    QList<int>indices = outputDeviceFormatIndices();
-    ui.outputFormatCombo->clear();
-    for (int i=0; i<indices.size(); i++) {
-      int k = indices[i];
-      ui.outputFormatCombo->addItem(formatList[k].getDescription(), QVariant(k));
-    }
-    setComboToFormat(ui.outputFormatCombo, fmt, false);
-  }
-  else {
-    ui.outputStackedWidget->setCurrentWidget(ui.outputDevicePage);
-    ui.outputDevicePage->setEnabled(false);
-  }
-  fmtChgInterlock = false;
-}
-
-//------------------------------------------------------------------------
-QString MainDlg::filterForFormat(int idx)
-{
-  QString str = formatList[idx].getDescription();
-  str += " (";
-  QStringList extensions = formatList[idx].getExtensions();
-  for (int i=0; i<extensions.size(); i++) {
-    if (i!= 0)
-      str += " ";
-    str += "*." + extensions[i];
-  }
-  str += ");;All Files (*.*)";
-  return str;
-}
-
-//------------------------------------------------------------------------
-int MainDlg::currentComboFormatIndex(QComboBox *comboBox)
-{
-  int idx = comboBox->currentIndex();
-  if (idx<0 || idx >= comboBox->count()) {
-    QMessageBox::critical(0, appName,
-                        "*** Internal Error -- current combo index is invalid!");
-    return 0;
-  }
-  return comboBox->itemData(idx).toInt();
-}
-//------------------------------------------------------------------------
-void MainDlg::browseInputFile()
-{
-  QString startFile = bd.inputFileNames.size() ? bd.inputFileNames[0] : bd.inputBrowse;
-  int idx = currentComboFormatIndex(ui.inputFormatCombo);
-  QStringList userList = 
-    QFileDialog::getOpenFileNames(0, tr("Select one or more input files"),
-                                 startFile, 
-                                 filterForFormat(idx));
-  if (userList.size()) {
-    bd.inputBrowse = userList[0];
-    bd.inputFileNames = userList;
-    QString str;
-    for (int i=0; i<bd.inputFileNames.size(); i++) {
-      if (i != 0) 
-       str += ", ";
-      str += "\"" + bd.inputFileNames[i] + "\"";
-    }
-    ui.inputFileNameText->setText(str);
-  }
-}
-
-//------------------------------------------------------------------------
-void MainDlg::browseOutputFile()
-{
-  int idx = currentComboFormatIndex(ui.outputFormatCombo);
-  QString startFile = bd.outputFileName.length() == 0 ? bd.outputBrowse : bd.outputFileName;
-  QString str =
-    QFileDialog::getSaveFileName(0, tr("Output File Name"),
-                                startFile, 
-                                filterForFormat(idx));
-  if (str.length() != 0) {
-    bd.outputBrowse = str;
-    bd.outputFileName = str;
-    ui.outputFileNameText->setText(str);
-  }
-}
-
-//------------------------------------------------------------------------
-QList<int> MainDlg::inputFileFormatIndices()
-{
-  QList<int>indices;
-  for (int i=0; i<formatList.size(); i++) {
-    if (formatList[i].isReadSomething() && formatList[i].isFileFormat()) 
-      indices<<i;
-  }
-  return indices;
-}
-
-//------------------------------------------------------------------------
-QList<int> MainDlg::inputDeviceFormatIndices()
-{
-  QList<int>indices;
-  for (int i=0; i<formatList.size(); i++) {
-    if (formatList[i].isReadSomething() && formatList[i].isDeviceFormat()) 
-      indices<<i;
-  }
-  return indices;
-}
-
-//------------------------------------------------------------------------
-QList<int> MainDlg::outputFileFormatIndices()
-{
-  QList<int>indices;
-  for (int i=0; i<formatList.size(); i++) {
-    if (formatList[i].isWriteSomething() && formatList[i].isFileFormat()) 
-      indices<<i;
-  }
-  return indices;
-}
-
-//------------------------------------------------------------------------
-QList<int> MainDlg::outputDeviceFormatIndices()
-{
-  QList<int>indices;
-  for (int i=0; i<formatList.size(); i++) {
-    if (formatList[i].isWriteSomething() && formatList[i].isDeviceFormat()) 
-      indices<<i;
-  }
-  return indices;
-}
-
-//------------------------------------------------------------------------
-void MainDlg::loadFormats()
-{
-  if (!FormatLoad().getFormats(formatList)) {
-    QMessageBox::information(0, QString(appName), 
-                            tr("Error reading format configuration.  "
-                               "Check that the backend program \"gpsbabel\" is properly installed "
-                               "and is in the current PATH\n\n"
-                               "This program cannot continue."));
-    exit(1);
-  }
-  if (inputFileFormatIndices().size() == 0 ||
-      inputDeviceFormatIndices().size() == 0 ||
-      outputFileFormatIndices().size() == 0 ||
-      outputDeviceFormatIndices().size() == 0) {
-    QMessageBox::information(0, QString(appName), 
-                            tr("Some file/device formats were not found during initialization.  "
-                               "Check that the backend program \"gpsbabel\" is properly installed "
-                               "and is in the current PATH\n\n"
-                               "This program cannot continue."));
-    exit(1);
-  }
-}
-//------------------------------------------------------------------------
-static int iconIndex(bool a, bool b)
-{
-  return ((a?1:0)*2) + (b?1:0);
-}
-
-//------------------------------------------------------------------------
-void MainDlg::setIndicatorLights(QLabel *label, const QString type, int code) 
-{
-  label->setPixmap(lights[code]);
-  QString s;
-  switch (code) 
-    {
-    default:
-    case 0:
-      s = tr("Input and output formats do not support %1").arg(type);
-      break;
-    case 1:
-      s = tr("Input does not support %1; output format supports %2").arg(type).arg(type);
-      break;
-    case 2:
-      s = tr("Input format supports %1; output format does not support %2").arg(type).arg(type);
-      break;
-    case 3:
-      s = tr("Both input and output formats support %1").arg(type);
-      break;
-    }
-  label->setToolTip(s);
-}
-
-//------------------------------------------------------------------------
-void MainDlg::crossCheckInOutFormats()
-{
-  if (ui.inputFormatCombo->count() == 0 ||
-      ui.outputFormatCombo->count() == 0) {
-    // During format/device switch this is true
-    return;
-  }
-  Format ifmt = formatList[currentComboFormatIndex(ui.inputFormatCombo)];
-  Format ofmt = formatList[currentComboFormatIndex(ui.outputFormatCombo)];
-  
-  ui.xlateWayPtsCk->setEnabled(ifmt.isReadWaypoints() && ofmt.isWriteWaypoints());
-  ui.xlateTracksCk->setEnabled(ifmt.isReadTracks()    && ofmt.isWriteTracks());
-  ui.xlateRoutesCk->setEnabled(ifmt.isReadRoutes()    && ofmt.isWriteRoutes());
-  
-  setIndicatorLights(ui.wayPtLabel, tr("waypoints"), iconIndex(ifmt.isReadWaypoints(), ofmt.isWriteWaypoints()));
-  setIndicatorLights(ui.trackLabel, tr("tracks"), iconIndex(ifmt.isReadTracks(), ofmt.isWriteTracks()));
-  setIndicatorLights(ui.routeLabel, tr("routes"), iconIndex(ifmt.isReadRoutes(), ofmt.isWriteRoutes()));
-}
-
-//------------------------------------------------------------------------
-void MainDlg::displayOptionsText(QLineEdit *le, QComboBox *combo, bool isInput) 
-{
-  int fidx = combo->itemData(combo->currentIndex()).toInt();
-  if (isInput)
-    le->setText(MakeOptionsNoLeadingComma(formatList[fidx].getInputOptions()));
-  else 
-    le->setText(MakeOptionsNoLeadingComma(formatList[fidx].getOutputOptions()));
-
-}
-
-//------------------------------------------------------------------------
-void MainDlg::setComboToFormat(QComboBox *comboBox, const QString &name, bool isFile)
-{
-  int fidx = -1;
-  for (int i=0; i<formatList.size(); i++) {
-    if (formatList[i].getName() == name &&
-       formatList[i].isFileFormat() == isFile) {
-      fidx = i;
-      break;
-    }
-  }
-  if (fidx >=0) {
-    for (int i=0; i<comboBox->count(); i++) {
-      if (comboBox->itemData(i).toInt() == fidx) {
-       comboBox->setCurrentIndex(i);
-       break;
-      }
-    }
-  }
-}
-
-//------------------------------------------------------------------------
-void MainDlg::inputFormatChanged(int comboIdx) 
-{
-  if (fmtChgInterlock)
-    return;
-  int fidx = ui.inputFormatCombo->itemData(comboIdx).toInt();
-  ui.inputOptionsBtn->setEnabled(formatList[fidx].getInputOptions().size()>0);
-  displayOptionsText(ui.inputOptionsText,  ui.inputFormatCombo, true);
-  crossCheckInOutFormats();
-
-  if (ui.inputFileOptBtn->isChecked())
-    bd.inputFileFormat =formatList[fidx].getName();
-  else
-    bd.inputDeviceFormat = formatList[fidx].getName();
-}
-
-//------------------------------------------------------------------------
-void MainDlg::outputFormatChanged(int comboIdx) 
-{
-  if (fmtChgInterlock)
-    return;
-  int fidx = ui.outputFormatCombo->itemData(comboIdx).toInt();
-  ui.outputOptionsBtn->setEnabled(formatList[fidx].getOutputOptions().size()>0);
-  displayOptionsText(ui.outputOptionsText,  ui.outputFormatCombo, false);
-  crossCheckInOutFormats();
-
-  if (ui.outputFileOptBtn->isChecked())
-    bd.outputFileFormat =formatList[fidx].getName();
-  else if (ui.outputDeviceOptBtn->isChecked())
-    bd.outputDeviceFormat = formatList[fidx].getName();
-
-}
-
-//------------------------------------------------------------------------
-void MainDlg::inputOptionButtonClicked() 
-{
-  int fidx = currentComboFormatIndex(ui.inputFormatCombo);
-  OptionsDlg optionDlg(0, 
-                      formatList[fidx].getName(),
-                      formatList[fidx].getInputOptionsRef());
-  optionDlg.setWindowTitle(QString(appName) + " - " + tr("Options for %1").arg(formatList[fidx].getName()));
-  optionDlg.exec();
-  displayOptionsText(ui.inputOptionsText,  ui.inputFormatCombo, true);
-}
-
-//------------------------------------------------------------------------
-void MainDlg::outputOptionButtonClicked() 
-{
-  int fidx = currentComboFormatIndex(ui.outputFormatCombo);
-  OptionsDlg optionDlg(0, formatList[fidx].getName(), formatList[fidx].getOutputOptionsRef());
-  optionDlg.setWindowTitle(QString(appName) + " - " + tr("Options for %1").arg(formatList[fidx].getName()));
-  optionDlg.exec();
-  displayOptionsText(ui.outputOptionsText,  ui.outputFormatCombo, false);
-}
-
-
-//------------------------------------------------------------------------
-bool MainDlg::isOkToGo()
-{
-  if (!((ui.xlateWayPtsCk->isChecked() && ui.xlateWayPtsCk->isEnabled()) ||
-       (ui.xlateRoutesCk->isChecked() && ui.xlateRoutesCk->isEnabled()) ||
-       (ui.xlateTracksCk->isChecked() && ui.xlateTracksCk->isEnabled()))) {
-    QMessageBox::information(0, QString(appName), tr("No valid waypoints/routes/tracks translation specified"));
-    return false;
-  }
-  
-  if ((bd.inputType == BabelData::fileType) &&
-      (bd.inputFileNames.size() == 0)) {
-    QMessageBox::information(0, QString(appName), tr("No input file specified"));
-    return false;
-  }
-
-  if (bd.outputType == BabelData::noType && bd.previewGmap == true) {
-  }
-  if (bd.outputType == BabelData::noType && bd.previewGmap == false) {
-    QMessageBox::information(0, QString(appName), tr("No valid output specified"));
-    return false;
-  }
-  else if (bd.outputType == BabelData::fileType && 
-          bd.outputFileName.length() == 0) {
-    QMessageBox::information(0, QString(appName), tr("No output file specified"));
-    return false;
-  }
-  return true;
-}
-
-//------------------------------------------------------------------------
-bool MainDlg::runGpsbabel(const QStringList &args, QString &errorString, 
-                         QString &outputString)
-{
-  QProcess *proc = new QProcess(0);
-  QString name = "gpsbabel";
-  proc->start(name, args);
-  ProcessWaitDialog *waitDlg = new ProcessWaitDialog(0, proc);
-
-  if (proc->state() == QProcess::NotRunning) {
-    errorString = QString(tr("Process \"%1\" did not start")).arg(name);
-    return false;
-  }
-  
-  waitDlg->show();
-  waitDlg->exec();
-  int exitCode = -1;
-  bool retStatus = false;
-  if (waitDlg->getExitedNormally()) {
-    exitCode = waitDlg->getExitCode();
-    if (exitCode == 0)
-      retStatus = true;
-    else  {
-      errorString = 
-       QString(tr("Process exited unsucessfully with code %1"))
-       .arg(exitCode);
-      retStatus = false;
-    }
-  }
-  else {
-    retStatus = false;
-    errorString = waitDlg->getErrorString();
-  }
-  outputString = waitDlg->getOutputString();
-  delete proc;
-  delete waitDlg;
-  return retStatus;
-}
-
-//------------------------------------------------------------------------
-int MainDlg::formatIndexFromName(bool isFile, const QString &nm)
-{
-  for (int i= 0; i<formatList.size(); i++) {
-    if (nm == formatList[i].getName() && formatList[i].isFileFormat() == isFile)
-      return i;
-  }
-  return 0;
-}
-
-//------------------------------------------------------------------------
-QString MainDlg::charSetFromCombo(QComboBox *combo)
-{
-  int i = combo->itemData((combo->currentIndex())).toInt();
-  return (i >=0 ) ? charSets[i] : QString();
-}
-
-//------------------------------------------------------------------------
-void MainDlg::setComboToCharSet(QComboBox *combo, const QString &cset)
-{
-  for (int i=0; i<charSets.size(); i++) {
-    if (charSets[i] == cset) {
-      combo->setCurrentIndex(i+1); // first index is default;
-    }
-  }
-}
-//------------------------------------------------------------------------
-void MainDlg::applyClicked() 
-{
-  getWidgetValues();
-  if (!isOkToGo())
-    return;
-
-  QStringList args;
-
-  if (bd.debugLevel >=0)     args << QString("-D%1").arg(bd.debugLevel);
-  if (bd.synthShortNames)    args << "-s";
-
-  // Input char set if specified
-  if (bd.enableCharSetXform && bd.inputCharSet != QString()) 
-    args << "-c" << bd.inputCharSet;
-
-  if (bd.xlateWayPts)        args << "-w";
-  if (bd.xlateRoutes)        args << "-r";
-  if (bd.xlateTracks)        args << "-t";
-
-  // Input type, with options
-  bool iisFile = (bd.inputType == BabelData::fileType);
-  int fidx = formatIndexFromName(iisFile, iisFile ?
-                                bd.inputFileFormat : bd.inputDeviceFormat);
-  args << "-i";
-  args << (formatList[fidx].getName() + MakeOptions(formatList[fidx].getInputOptions()));
-  
-  // Input file(s) or device
-  if (bd.inputType == BabelData::fileType) {
-    for (int i=0; i<bd.inputFileNames.size(); i++) 
-      args << "-f" << bd.inputFileNames[i];
-  }
-  else {
-    args << "-f" << bd.inputDeviceName;
-  }
-
-  // --- Filters!
-  args << filterData.getAllFilterStrings();
-
-  // Output char set if specified
-  if (bd.enableCharSetXform && bd.outputCharSet != QString()) 
-    args << "-c" << bd.outputCharSet;
-
-  // Output type, with options
-  if (bd.outputType != BabelData::noType) {
-    bool outIsFile = (bd.outputType == BabelData::fileType);
-    fidx = formatIndexFromName(outIsFile, (outIsFile ?
-                                          bd.outputFileFormat : bd.outputDeviceFormat));
-    args << "-o";
-    args << (formatList[fidx].getName() + MakeOptions(formatList[fidx].getOutputOptions()));
-    
-    // output file or device option
-    if (outIsFile) {
-      if (bd.outputFileName != "")
-       args << "-F" << bd.outputFileName;
-    }
-    else if (bd.outputType == BabelData::deviceType) {
-      args << "-F" << bd.outputDeviceName;
-    }
-  }
-
-  // Now output for preview in google maps
-  QString tempName;
-  if (bd.previewGmap) {
-    QTemporaryFile ftemp;
-    ftemp.open();
-    tempName = ftemp.fileName();
-    ftemp.close();
-
-    // Ideally, expost this in the UI.  For now, just split the track
-    // if we've no recorded fixes for > 5 mins and we've moved > 300 meters.
-    args << "-x";
-    args << "track,pack,sdistance=0.3k,split=5m";
-
-    args << "-o";
-    args << "gpx";
-    args << "-F" << tempName;
-  }
-
-  ui.outputWindow->clear();
-  ui.outputWindow->appendPlainText("gpsbabel " + args.join(" "));
-
-  QString errorString, outputString;
-  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
-  bool x = runGpsbabel(args, errorString, outputString);
-  QApplication::restoreOverrideCursor();
-
-  ui.outputWindow->appendPlainText(outputString);
-  if (x) {
-    ui.outputWindow->appendPlainText(tr("Translation successful"));
-    if (bd.previewGmap) {
-      this->hide();
-      GMapDialog dlg(0, tempName, bd.debugLevel >=1 ? ui.outputWindow : 0);
-      dlg.show();
-      dlg.exec();
-      this->show();
-    }
-  }
-  else 
-    ui.outputWindow->appendPlainText(tr("Error running gpsbabel: %1\n").arg(errorString));
-}
-
-//------------------------------------------------------------------------
-void MainDlg::rejectedClicked() 
-{
-  saveSettings();
-  reject();
-}
-
-//------------------------------------------------------------------------
-void MainDlg::closeEvent(QCloseEvent*)  
-{
-  saveSettings();
-  reject();
-}
-//------------------------------------------------------------------------
-void MainDlg::setComboToDevice(QComboBox *comboBox, const QString &name)
-{
-  for (int i=0; i<comboBox->count(); i++) {
-    if (comboBox->itemText(i) == name) {
-      comboBox->setCurrentIndex(i);
-      break;
-    }
-  }
-}
-
-//------------------------------------------------------------------------
-void MainDlg::saveSettings()
-{
-  getWidgetValues();
-
-  QSettings settings;
-  bd.saveSettings(settings);
-  for (int i=0; i<formatList.size(); i++) 
-    formatList[i].saveSettings(settings);
-  for (int i=0; i<filterData.filters.size(); i++)
-    filterData.filters[i]->saveSettings(settings);
-}
-
-//------------------------------------------------------------------------
-void MainDlg::restoreSettings()
-{
-  QSettings settings;
-  bd.restoreSettings(settings);
-  for (int i=0; i<formatList.size(); i++) 
-    formatList[i].restoreSettings(settings);
-
-  for (int i=0; i<filterData.filters.size(); i++)
-    filterData.filters[i]->restoreSettings(settings);
-
-  setWidgetValues();
-}
-
-//------------------------------------------------------------------------
-void MainDlg::resetFormatDefaults()
-{
-  int ret = QMessageBox::warning
-    (this, QString(appName),
-     tr("Are you sure you want to reset all format options to default values?"),
-     QMessageBox::Yes | QMessageBox::No);
-  if (ret == QMessageBox::Yes) {
-    for (int i=0; i<formatList.size(); i++) 
-      formatList[i].setToDefault();
-    displayOptionsText(ui.inputOptionsText,  ui.inputFormatCombo, true);
-    displayOptionsText(ui.outputOptionsText,  ui.outputFormatCombo, false);
-  }
-}
-
-//------------------------------------------------------------------------
-void MainDlg::moreOptionButtonClicked()
-{
-  AdvDlg advDlg(0, bd.synthShortNames, 
-               bd.forceGPSTypes, bd.enableCharSetXform, bd.previewGmap, bd.debugLevel);
-  connect(advDlg.formatButton(), SIGNAL(clicked()),
-         this, SLOT(resetFormatDefaults()));
-  advDlg.exec();
-  checkCharSetCombos();
-}
-//------------------------------------------------------------------------
-void MainDlg::aboutClicked()
-{
-  AboutDlg aboutDlg(0, babelVersion, QString(appName) + " Version 0.11");
-  aboutDlg.setWindowTitle(tr("About %1").arg(appName));
-  aboutDlg.exec();
-}
-
-//------------------------------------------------------------------------
-void MainDlg::helpClicked()
-{
-  ShowHelp("gpsbabel.html");
-}
-//------------------------------------------------------------------------
-void MainDlg::filtersClicked()
-{
-  FilterDialog dlg(0, filterData);
-  dlg.runDialog();
-  updateFilterStatus();
-}
-
-
-//------------------------------------------------------------------------
-void MainDlg::updateFilterStatus()
-{
-  bool filterActive = filterData.getAllFilterStrings().size();
-  ui.filterStatus->setEnabled(filterActive);
-  if (filterActive) 
-    ui.filterStatus->setToolTip(tr("One or more data filters are active"));
-  else {
-    ui.filterStatus->setToolTip(tr("No data filters are active"));
-  }
-}
-//------------------------------------------------------------------------
-void MainDlg::setWidgetValues()
-{
-  if (bd.inputType == BabelData::fileType) {
-    ui.inputFileOptBtn->setChecked(true);
-    inputFileOptBtnClicked();
-    setComboToFormat(ui.inputFormatCombo, bd.inputFileFormat, true);
-    ui.inputStackedWidget->setCurrentWidget(ui.inputFilePage);
-  }
-  else {
-    ui.inputDeviceOptBtn->setChecked(true);
-    inputDeviceOptBtnClicked();
-    setComboToFormat(ui.inputFormatCombo, bd.inputDeviceFormat, false);
-    ui.inputStackedWidget->setCurrentWidget(ui.inputDevicePage);
-  }
-  setComboToDevice(ui.inputDeviceNameCombo, bd.inputDeviceName);
-  setComboToCharSet(ui.inputCharSetCombo, bd.inputCharSet);
-
-  if (bd.outputType == BabelData::fileType) {
-    ui.outputFileOptBtn->setChecked(true);
-    outputFileOptBtnClicked();
-    setComboToFormat(ui.outputFormatCombo, bd.outputFileFormat, true);
-    ui.outputStackedWidget->setCurrentWidget(ui.outputFilePage);
-  }
-  else if (bd.outputType == BabelData::deviceType) {
-    ui.outputDeviceOptBtn->setChecked(true);
-    outputDeviceOptBtnClicked();
-    setComboToFormat(ui.outputFormatCombo, bd.outputDeviceFormat, false);
-    ui.outputStackedWidget->setCurrentWidget(ui.outputDevicePage);
-  }
-  else {
-    ui.outputFileOptBtn->setChecked(false);
-    ui.outputDeviceOptBtn->setChecked(false);
-    setComboToFormat(ui.outputFormatCombo, bd.outputFileFormat, true);
-    ui.outputStackedWidget->setCurrentWidget(ui.outputFilePage);
-    ui.outputFilePage->setDisabled(true);
-  }
-
-  setComboToDevice(ui.outputDeviceNameCombo, bd.outputDeviceName);
-  setComboToCharSet(ui.outputCharSetCombo, bd.outputCharSet);
-
-  ui.xlateWayPtsCk->setChecked(bd.xlateWayPts);
-  ui.xlateTracksCk->setChecked(bd.xlateTracks);
-  ui.xlateRoutesCk->setChecked(bd.xlateRoutes);
-
-  crossCheckInOutFormats();
-  displayOptionsText(ui.inputOptionsText,  ui.inputFormatCombo, true);
-  displayOptionsText(ui.outputOptionsText,  ui.outputFormatCombo, false);
-
-  checkCharSetCombos();
-  updateFilterStatus();
-}
-
-//------------------------------------------------------------------------
-void MainDlg::getWidgetValues()
-{
-  int comboIdx = ui.inputFormatCombo->currentIndex();
-  int fidx = ui.inputFormatCombo->itemData(comboIdx).toInt();
-  if (ui.inputFileOptBtn->isChecked()){
-    bd.inputType = BabelData::fileType;
-    bd.inputFileFormat =formatList[fidx].getName();
-  }
-  else {
-    bd.inputType = BabelData::deviceType;
-    bd.inputDeviceFormat =formatList[fidx].getName();
-  }
-  bd.inputDeviceName = ui.inputDeviceNameCombo->currentText();
-  bd.inputCharSet = charSetFromCombo(ui.inputCharSetCombo);
-
-  comboIdx = ui.outputFormatCombo->currentIndex();
-  fidx = ui.outputFormatCombo->itemData(comboIdx).toInt();
-  if (ui.outputFileOptBtn->isChecked()){
-    bd.outputType = BabelData::fileType;
-    bd.outputFileFormat =formatList[fidx].getName();
-  }
-  else if (ui.outputDeviceOptBtn->isChecked()){
-    bd.outputType = BabelData::deviceType;
-    bd.outputDeviceFormat =formatList[fidx].getName();
-  }
-  else {
-    bd.outputType = BabelData::noType;
-  }
-  bd.outputDeviceName = ui.outputDeviceNameCombo->currentText();
-  bd.outputCharSet = charSetFromCombo(ui.outputCharSetCombo);
-
-  bd.xlateWayPts = ui.xlateWayPtsCk->isChecked();
-  bd.xlateTracks = ui.xlateTracksCk->isChecked();
-  bd.xlateRoutes = ui.xlateRoutesCk->isChecked();
-}
-
-
diff --git a/gui/maindlg.h b/gui/maindlg.h
deleted file mode 100644 (file)
index a6c1dab..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-// -*- C++ -*-
-// $Id: maindlg.h,v 1.1 2009/07/05 21:14:56 robertl Exp $
-//------------------------------------------------------------------------
-//
-//  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
-//
-//  This program is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU General Public License as
-//  published by the Free Software Foundation; either version 2 of the
-//  License, or (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111
-//  USA
-//
-#ifndef MAINDLG_H
-#define MAINDLG_H
-
-#include "ui_mainui.h"
-#include "persistdlg.h"
-#include "format.h"
-#include "filterdata.h"
-#include "babeldata.h"
-
-class MainDlg: public PersistentDialog {
-  Q_OBJECT
-
-  
-  public:
-  MainDlg(QWidget* parent);
-
-private:
-  Ui_MainDlg     ui;
-  QList<Format>  formatList;
-  QString        babelVersion;
-  QPixmap        lights[4];
-  QStringList    charSets;
-  AllFiltersData filterData;
-  BabelData      bd;
-  bool           fmtChgInterlock;
-
-private:
-  void loadFormats();
-  QString filterForFormat(int idx);
-  int  formatIndexFromName(bool isFile, const QString &);
-  QList<int>inputFileFormatIndices();
-  QList<int>inputDeviceFormatIndices();
-  QList<int>outputFileFormatIndices();
-  QList<int>outputDeviceFormatIndices();
-  int  currentComboFormatIndex(QComboBox *comboBox);
-  bool isOkToGo();
-  bool runGpsbabel(const QStringList &args, QString &errorString, QString &outputString);
-  void crossCheckInOutFormats();
-  void setIndicatorLights(QLabel *label, const QString type, int code) ;
-  void displayOptionsText(QLineEdit *, QComboBox *, bool);
-
-  void saveSettings();
-  void restoreSettings();
-  void setComboToFormat(QComboBox *comboBox, const QString &, bool isFile);
-  void setComboToDevice(QComboBox *comboBox, const QString &);
-
-  void loadDeviceNameCombos();
-  void loadCharSetCombos();
-  void checkCharSetCombos();
-  QString charSetFromCombo(QComboBox *);
-  void setComboToCharSet(QComboBox *, const QString &);
-  void updateFilterStatus();
-  void setWidgetValues();
-  void getWidgetValues();
-
-protected:
-  void closeEvent(QCloseEvent*);
-
- private slots:
-  void inputFileOptBtnClicked();
-  void inputDeviceOptBtnClicked();
-  void inputOptionButtonClicked();
-  void inputFormatChanged(int);
-  void browseInputFile();
-  void outputFileOptBtnClicked();
-  void outputDeviceOptBtnClicked();
-  void outputOptionButtonClicked();
-  void outputFormatChanged(int);
-  void browseOutputFile();
-  void moreOptionButtonClicked();
-  void applyClicked();
-  void rejectedClicked();
-  void aboutClicked();
-  void helpClicked();
-  void filtersClicked();
-  void resetFormatDefaults();
-
-};
-
-
-#endif
diff --git a/gui/persistdlg.cpp b/gui/persistdlg.cpp
deleted file mode 100644 (file)
index a0bb2dc..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-// -*- C++ -*-
-// $Id: persistdlg.cpp,v 1.1 2009/07/05 21:14:56 robertl Exp $
-//------------------------------------------------------------------------
-//
-//  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
-//
-//  This program is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU General Public License as
-//  published by the Free Software Foundation; either version 2 of the
-//  License, or (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111
-//  USA
-//
-//------------------------------------------------------------------------
-
-#include "persistdlg.h"
-#include <QApplication>
-#include <QCloseEvent>
-
-
-PersistentDialog::PersistentDialog(QWidget *parent): 
-  QWidget(parent, Qt::Dialog)
-{
-  returnValue = 0;
-  setWindowModality(Qt::WindowModal);
-}
-
-PersistentDialog::~PersistentDialog()
-{
-}
-
-
-void PersistentDialog::accept()
-{
-  returnValue = 1;
-  eventLoop->exit(1);
-}
-
-void PersistentDialog::reject()
-{
-  returnValue = 0;
-  eventLoop->exit();
-}
-
-int PersistentDialog::exec()
-{
-  returnValue = 0;
-  show();
-
-  QEventLoop evl;
-  eventLoop = &evl;
-  (void) eventLoop->exec();
-  hide();
-  return returnValue;
-}
-
-void PersistentDialog::closeEvent(QCloseEvent*)  
-{
-  //eventLoop->exit();
-  reject();
-}
diff --git a/gui/persistdlg.h b/gui/persistdlg.h
deleted file mode 100644 (file)
index d978d8f..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-// -*- C++ -*-
-// $Id: persistdlg.h,v 1.1 2009/07/05 21:14:56 robertl Exp $
-//------------------------------------------------------------------------
-//
-//  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
-//
-//  This program is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU General Public License as
-//  published by the Free Software Foundation; either version 2 of the
-//  License, or (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111
-//  USA
-//
-//------------------------------------------------------------------------
-//
-// A dialog that will prevent the escape key from closing it.  Also no
-// default buttons, and "ENTER" key actions.  Needed so that you won't
-// lose all the edited data --- The regular Qt QDialog has no way of
-// bypassing ESC key.
-// 
-#ifndef PERSISTDLG_H
-#define PERSISTDLG_H
-
-#include <QWidget>
-#include <QEventLoop>
-
-class PersistentDialog: public QWidget
-{
-Q_OBJECT
- public: 
-  PersistentDialog(QWidget *parent = 0);
-  ~PersistentDialog();
-  int exec();
-
-protected:
-  void closeEvent(QCloseEvent*ev);
-
-protected slots:
-  void accept();
-  void reject();
-
-private:
-  int returnValue;
-  QEventLoop *eventLoop;
-};
-
-
-
-#endif
-